package com.wc.blue_bridge_history.Java15B.D_食堂;

import java.util.Scanner;

/**
 * @Author congge
 * @Date 2024/4/13 13:12
 * @description
 */
public class Main {
    static Scanner sc = new Scanner(System.in);
    static int a, b, c, d, e, q, res, desk;

    public static void main(String[] args) {
        q = sc.nextInt();
        while (q-- > 0) {
            a = sc.nextInt();
            b = sc.nextInt();
            c = sc.nextInt();
            d = sc.nextInt();
            e = sc.nextInt();
            res = 0;
            // 检查4人桌 适配 4人寝室
            if (c > 0 && d > 0) {
                desk = Math.min(c, d);
                res += desk * 4;
                c -= desk;
                d -= desk;
            }
            // 检查6人桌 适配 3人寝室
            if (e > 0 && b >= 2) {
                desk = Math.min(b / 2, e);
                res += desk * 6;
                b -= desk * 2;
                e -= desk;
            }
            // 坐完的适配的之后，开始拼桌子
            // 4 + 2 = 6
            if (e > 0 && a > 0 && c > 0) {
                desk = Math.min(Math.min(a, c), e);
                e -= desk;
                res += desk * 6;
                a -= desk;
                c -= desk;
            }
            // 2 * 3 = 6
            if (e > 0 && a >= 3) {
                desk = Math.min(a / 3, e);
                e -= desk;
                res += desk * 6;
                a -= desk * 3;
            }
            // 2 + 3 = 5
            if (e > 0 && a > 0 && b > 0) {
                desk = Math.min(Math.min(a, b), e);
                a -= desk;
                b -= desk;
                res += desk * 5;
            }
            // 2 * 2 = 4;
            if (d > 0 && a >= 2) {
                desk = Math.min(d, a / 2);
                a -= desk * 2;
                d -= desk;
                res += desk * 4;
            }
            // 6个坐4人
            if (e > 0 && c > 0) {
                desk = Math.min(e, c);
                c -= desk;
                e -= desk;
                res += desk * 4;
            }
            // 6个坐3人
            if (e > 0 && b > 0) {
                desk = Math.min(e, b);
                b -= desk;
                e -= desk;
                res += desk * 3;
            }
            // 6个坐2人
            if (e > 0 && a > 0) {
                desk = Math.min(e, a);
                a -= desk;
                e -= desk;
                res += desk * 2;
            }
            // 4人桌坐3人
            if (d > 0 && b > 0) {
                desk = Math.min(d, b);
                d -= desk;
                b -= desk;
                res += desk * 3;
            }
            // 4人桌子坐2人
            if (d > 0 && a > 0) {
                desk = Math.min(d, a);
                d -= desk;
                a -= desk;
                res += desk * 2;
            }
            System.out.println(res);
        }
    }
}
